﻿using System;
using System.IO;

namespace dk.Helper.Base.Core
{
    public class WorldInitializer : IWorldInitializer
    {
        #region IWorldInitializer Members

        /// <summary>
        /// Inits this instance.
        /// </summary>
        /// <param name="world">The world.</param>
        public void Init(IWorld world)
        {
            IVillageDataReader villageDataReader = new VillageDataReader();
            world.Villages = villageDataReader.CreateVillages(GetFilePath(world, "village.txt"));
            IPlayerDataReader playerDataReader = new PlayerDataReader(world.Villages);
            world.Players = playerDataReader.CreatePlayers(GetFilePath(world, "player.txt"));
            IAllyDataReader allyDataReader = new AllyDataReader(world.Players);
            world.Allies = allyDataReader.CreateAllies(GetFilePath(world, "ally.txt"));
        }

        #endregion

        /// <summary>
        /// Gets the file path.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        private string GetFilePath(IWorld world, string filename)
        {
            return Path.Combine(Path.Combine(Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "dk.Helper"),
                                             world.Name),
                                filename);
        }
    }
}